<template>
	<view class="tabbar">
		<!-- tabbar -->
		<u-tabbar
			:list="$getState('tabbar', 'list')"
			height="120"
			bg-color="#ffffff"
			inactive-color="#d0cfd0"
			active-color="#7089f1"
			icon-size="56"
			:mid-button="true"
			mid-button-size="60"
			:borderTop="false"
			:before-switch="beforeSwitch"
		/>
	</view>
</template>

<script>
import { getToken } from '@/utils/user'
import { actionScheme, getCurrentScheme } from '@/utils/scheme'
export default {
  methods: {
    /**
     * 点击前校验
     */
    beforeSwitch(index) {
      if (index === 1) { // 点击中间
        this.onclickMidBtn()
      } else {
        actionScheme({ scheme: this.$getState('tabbar', 'list')[ index ].scheme })
      }

      return false
    },
    /**
     * 点击中间按键
     */
    async onclickMidBtn() {
      if (!getToken()) {
        this.$router.navigateToLogin({ scheme: getCurrentScheme() }, () => {
          this.$msg('需要登录才能使用该功能')
        })
        return
      }
      const res = await this.$menuPicker([
        { label: '创建竞赛项目', fn: () => this.$router.navigatorCreateProject('competition') },
        { label: '创建课设项目', fn: () => this.$router.navigatorCreateProject('courseDesign') },
        // { label: '创建队伍', fn: this.$router.navigateToCreateTeam },
        // { label: '发布帖子', fn: this.$router.navigateToEditForum },
      ])

      res.fn()
    }
  }
}
</script>

/* style需要直接修改组件里的样式 */

